const { tool,time,api } = getApp();
Page({

    data: {
        open_id: '',
        team_id: '',        // 小组 id
        invitation_code: '',// 邀请码
    },

    // 表单输入
    input(e) {
        let { value } = e.detail;
        this.setData({ invitation_code: value });
    },

    // 提交表单
    submit() {
        let { open_id,team_id,invitation_code } = this.data;
        if (invitation_code) {
            tool.joinTeam({ open_id,team_id,invitation_code }).then(res => {
                api.showToast('加入成功','success');
                setTimeout(() => {
                    api.switchTab('/pages/class/list/index');
                }, 1500);
            })
        } else api.showToast('邀请码不能为空','none');
    },

    // 页面加载
    onLoad(options) {
        let { team_id } = options;
        tool.getUserInfo().then(info => {
            let { open_id } = info;
            if (info.team_id) {
                api.showModal('提示','您已加入其他小组，无法参与此邀请',false).then(res => {
                    api.switchTab('/pages/class/list/index');
                });
            } else this.setData({ team_id,open_id });
        })
    },
    
})